#获取所有的tr标签
#第二个tr标签
#class 为event的tr标签

#获取所有a标签的 href 属性

#获取所有的职位信息

from lxml import etree

parser = etree.HTMLParser(encoding='utf-8')
html = etree.parse('tencent.html',parser=parser)

#以上时间 将 将字符串解析成HTML文档
#按照字符串的标签将其序列化

#获取所有的 tr标签
# trs = html.xpath("//tr")
# for tr in trs:
#     print(etree.tostring(tr,encoding='utf-8').decode('utf-8'))

#获取所有的第二个tr标签 xpath 函数返回的是一个列表
# trs = html.xpath("//tr[2]")[0]
# for tr in trs:
#     print(etree.tostring(tr,encoding='utf-8').decode('utf-8'))

#class 为event的tr标签

# trs = html.xpath("//tr[@class='even']")
# for tr in trs:
#     print(etree.tostring(tr,encoding='utf-8').decode('utf-8'))

#获取所有a标签下的  href 属性
# aList = html.xpath("//a/@href")
# # for tr in trs:
# #     print(etree.tostring(tr,encoding='utf-8').decode('utf-8'))
# for a in aList:
#     print("http://hr.tencent.com/"+a)

#获取所有职位的信息

trs = html.xpath("//tr[position()>1]")
positions = []
for tr in trs:
    href = tr.xpath(".//a/@href")[0]
    fullurl = 'http://hr.qfedu.com/'+href
    title = tr.xpath("./td[1]//text()")[0]
    category = tr.xpath("./td[2]//text()")[0]
    nums = tr.xpath("./td[3]//text()")[0]
    address = tr.xpath("./td[4]//text()")[0]
    pubtime = tr.xpath("./td[5]//text()")[0]
    position = {
        'url':fullurl,
        'title':title,
        'category':category,
        'nums':nums,
        'address':address,
        'pubtime':pubtime,
    }
    positions.append(position)

print(positions)

